﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using ConstructionBidOnline.Biz;

public partial class AddToFavorite : System.Web.UI.Page
{

    #region Public Properties

    public CompanyInformation CompanyObj;
    bool MemberIsValid = false;

    #endregion

    #region Event Handlers

    #region Page Load

    protected void Page_Load(object sender, EventArgs e)
    {
        CompanyObj = CompanyInformation.GetCompanyInformationByID(Int32.Parse(Request.QueryString["CompanyID"].ToString()));
        txtcontractorname.Text = CompanyObj.Companyname;
        txtcontractorid.Text = CompanyObj.CompanyID.ToString();
        lblerror.Visible = false;
        if (Session["username"] == null)
        {
            pnllogin.Visible = true;
            pnladdtowatchlist.Visible = false;
        }
        else
        {
            pnllogin.Visible = false;
            pnladdtowatchlist.Visible = true;
        }

    }

    #endregion

    #region Add to Favorite Submit Click

    protected void btnAFLSubmit_Click(object sender, ImageClickEventArgs e)
    {
        FavoriteList fllist = FavoriteList.GetFavoriteListByUserID_FavoriteID(Int32.Parse(Session["userid"].ToString()), Int32.Parse(txtcontractorid.Text));
        if(fllist != null)
        {
            lblerror.Visible = true;
            lblerror.Text = "You have already added this contractor to your favorite list.";
        }
        else
        {
            FavoriteList flobj = FavoriteList.CreateNew();
            flobj.UserID = Int32.Parse(Session["userid"].ToString());
            flobj.FavoriteID = Int32.Parse(txtcontractorid.Text);
            flobj.Remark = txtcomment.Text;
            flobj.FavoriteName = txtcontractorname.Text;
            flobj.AddedDate = DateTime.Now;
            FavoriteList.Update(flobj);
            lblerror.Visible = true;
            lblerror.Text = "Contractor added to your favorite list";
        }
    }

    #endregion

    #region Login Submit Click

    protected void bttnLoginSubmit_Click(object sender, ImageClickEventArgs e)
    {
        string errMsg = "";
        RegisteredUser.RbsError result = RegisteredUser.LogonUser(txtUserName.Text, txtpassword.Text, out errMsg);
        if (result == RegisteredUser.RbsError.NO_ERROR)
        {
            lblloginerror.Text = "";
            RegisteredUser ruobj = RegisteredUser.GetUserByUserName(txtUserName.Text);
            Session["username"] = ruobj.FirstName + " " + ruobj.LastName;
            Session["userid"] = ruobj.RegisteredUserID;
            pnllogin.Visible = false;
            pnladdtowatchlist.Visible = true;
            MemberIsValid = true;
        }
        else
        {
            lblloginerror.Visible = true;
            lblloginerror.Text = errMsg;
        }
    }

    #endregion

    #endregion

}
